﻿
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "log.h"
#include "toolfun.h"
#include "haskelltool.h"
#include "barcode.h"

#include <algorithm>
#include <vector>
#include <functional>
#include <iostream>

//typedef std::function< int(share_zone_t&, share_queue_t&, share_grid_t &)> GridFunType;
#define     Min(a,b)    (a) < (b)? (a) : (b)
typedef std::function< int(int, int)> zipFunT;
void logInfoP(const char *fmt, ...);

template <typename T>
static  std::vector<T> zipWith(zipFunT fun,  std::vector<T>& list1, std::vector<T> &list2)
{
    int size = std::min(list1.size(), list2.size());
    std::vector<T> resultList;
    for(int i = 0; i < size; i++)
    {
        int result = fun(list1[i], list2[i]);
        resultList.push_back(result);
    }
    return resultList;
}
template <typename T>
static T add(T x1, T x2)
{
    return x1 + x2;
}

template <typename T>
static T diff(T x1, T x2)
{
    return x1 - x2;
}


template <typename T>
static  void printVector( std::vector<T> list, const char *prestr)
{
    std::cerr<<prestr<<"[ ";
    //logInfoP("%s[ ", prestr);
    for(int i = 0; i < list.size(); i++)
    {
        //logInfoP("%d ", list[i]);
        std::cerr<<list[i]<<" ";
    }
    std::cerr<<"]\n";

}
int main_barcode2()
{
    logInfo("***************BarCode*************");
    std::vector<int> x1 {1,2,3,4};
    std::vector<int> x2{100,1000,100,1000};
    std::vector<int> list3 = zipWith<int>(add<int>,x1,x2);

    printVector<int>(x1, "x1");
    printVector<int>(x2, "x2");
    printVector<int>(list3, "resultVector");

    std::vector<int> list4 = zipWith<int>(diff<int>,x1,x2);
    printVector<int>(list4, "result diff");


    return 0;
}
